import { IWangEditor } from './../types';

export const useWangEditor = (editor: IWangEditor) => {
  const toggleEnable = (readOnly: boolean) => {
    if (!editor.current) return;
    if (readOnly) {
      editor.current.disable();
    } else {
      editor.current.enable();
    }
  };

  const destroyEditor = () => {
    if (editor.current === null) return;
    editor.current.destroy();
    editor.current = null;
  };

  return {
    toggleEnable,
    destroyEditor,
  };
};
